<template>
  <view>
    <slot :title="title" :text="text">
      <view v-if="isShowFg" class="real-top">
        <rich-text :nodes="text" />
      </view>
    </slot>
  </view>
</template>

<script>
import api from '@/common/api.js';

export default {
  name: 'ChooseAgreement',

  props: {
    typeFlag: {
      type: [Number, String],
      default: '',
    },

    value: {
      type: String,
      default: '',
    },

    isShowFg: {
      type: Boolean,
      default: false,
    },
  },

  model: {
    prop: 'value',
    event: 'update:value',
  },

  data() {
    return {
      text: '',
      title: '',
    };
  },

  created() {
    api
      .getSysAppMore({
        sysCode: this.$GLOBAL.SYS_CODE,
        typeFlag: this.typeFlag,
      })
      .then(
        ({ result, code }) => {
          if (code == 0) {
            const { content, title } = result;
            this.text = content;
            this.title = title;

            this.$emit('getResult', {
              title,
              text: content,
            });
            this.$emit('update:value', content);
          }
        },
        () => {
          this.text = '未获取到协议' + this.typeFlag;
          this.$emit('update:value', this.text);
        }
      );
  },
};
</script>

<style lang="scss" scoped>
.real-top {
  // min-height: 56upx;
  padding: 10upx 30upx;
  background: rgba(255, 163, 78, 0.0706);
  text-align: left;
  color: #ff8053;
  font-size: 28upx;
}
</style>
